<?php

namespace Wap\Model;

class AlipayModel extends BaseModel {

    /**
     * 生成WAP支付宝链接
     * @param type $order
     */
    public function createAlipayUrl($order) {
        header("Content-type:text/html;charset=utf-8");
        $alipay_config = C("alipay_config");
        //商户的私钥（后缀是.pen）文件相对路径
        $alipay_config['private_key_path'] = './alipay/key/rsa_private_key.pem';
//支付宝公钥（后缀是.pen）文件相对路径
        $alipay_config['ali_public_key_path'] = './alipay/key/alipay_public_key.pem';
        Vendor('Alipay.lib.alipay_submit');
        //支付类型
        $payment_type = "1";
        //必填，不能修改
        //服务器异步通知页面路径
        $notify_url = C('WEB_URL') . "/index.php/Api/Alipay/notify";
        //需http://格式的完整路径，不能加?id=123这类自定义参数
        //页面跳转同步通知页面路径
        $return_url = C('WEB_URL') . "/index.php/Wap/Alipay/return_url";
        //需http://格式的完整路径，不能加?id=123这类自定义参数，不能写成http://localhost/
        //商户订单号
        $out_trade_no = $order['orderSN'];
        //商户网站订单系统中唯一订单号，必填
        //订单名称
        $subject = '玉都微店';
        //必填
        //付款金额
        $total_fee = $order['priceSum'];
        //必填
        //商品展示地址
        $show_url = C('WEB_URL');
        //必填，需以http://开头的完整路径，例如：http://www.商户网址.com/myorder.html
        //订单描述
        $body = '';
        //选填
        //超时时间
        $it_b_pay = '';
        //选填
        //钱包token
        $extern_token = '';
        //选填
//构造要请求的参数数组，无需改动
        $parameter = array(
            "service" => "alipay.wap.create.direct.pay.by.user",
            "partner" => trim($alipay_config['partner']),
            "seller_id" => trim($alipay_config['seller_id']),
            "payment_type" => $payment_type,
            "notify_url" => $notify_url,
            "return_url" => $return_url,
            "out_trade_no" => $out_trade_no,
            "subject" => $subject,
            "total_fee" => $total_fee,
            "show_url" => $show_url,
            "body" => $body,
            "it_b_pay" => $it_b_pay,
            "extern_token" => $extern_token,
            "_input_charset" => trim(strtolower($alipay_config['input_charset']))
        );

//建立请求
        $alipaySubmit = new \AlipaySubmit($alipay_config);
        $html_text = $alipaySubmit->buildRequestForm($parameter, "post", "确认");

        return $html_text;
    }

}
